package Offer.offer2018;

import java.util.Stack;

/**
 * 栈的弹出序列
 * Created by 雷文康 on 2018/3/4.
 */
public class Test22 {

    public static boolean isPopOrder(int[] pushArr, int[] popArr) {
        if (pushArr == null || pushArr.length == 0 || popArr == null || popArr.length == 0) {
            return false;
        }
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushArr.length; i++) {
            stack.push(pushArr[i]);
            while (j < popArr.length && stack.peek() == popArr[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }

}
